package com.itheima.article.controller;

import com.itheima.article.dto.ArticleHomeDto;
import com.itheima.article.dto.ArticleInfoDto;
import com.itheima.article.pojo.ApArticle;
import com.itheima.article.service.ApArticleService;
import com.itheima.common.dto.PageRequestDto;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AddArticleInfoController {
    @Autowired
    private ApArticleService apArticleService;
    /**
     * 远程调用文章库微服务进行添加文章
     * @param articleInfoDto 接收数据
     * @return 返回是否添加成功
     */
    @PostMapping("/api/add/ArticleInfoDto")
    ResultVo addArticleInfoDtoFeign(@RequestBody ArticleInfoDto articleInfoDto){
        if (apArticleService.addArticleInfo(articleInfoDto).isSuccess()){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @PostMapping("/article/loadmore")
    public PageResultVo loadMore(@RequestBody ArticleHomeDto homeDto){
        Integer loadType = 1;
        return apArticleService.findPage(homeDto,loadType);
    }
    @PostMapping("/article/load")
    public PageResultVo load(@RequestBody ArticleHomeDto homeDto){
        Integer loadType = 2;
        return apArticleService.findPage(homeDto,loadType);
    }
    @PostMapping("/article/loadnew")
    public PageResultVo loadNew(@RequestBody ArticleHomeDto homeDto){
        Integer loadType = 2;
        return apArticleService.findPage(homeDto,loadType);
    }
}
